home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4736 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  4.8 KB

  1. Path: news.compuserve.com!newsmaster
  2. From: 71024.1713@compuserve.com
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: OWL:  Palette problem - Please HELP!
  5. Date: Wed, 31 Jan 1996 22:31:09 GMT
  6. Organization: CompuServe Incorporated
  7. Message-ID: <4eoqj4$r83@dub-news-svc-5.compuserve.com>
  8. References: <4elus8$e5m@bigboote.WPI.EDU>
  9. NNTP-Posting-Host: hd83-002.compuserve.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. kevint@wpi.edu (Kevin Theroux) wrote:
  13.  
  14.  
  15.  
  16. >Hi there,
  17. >I hope someone out there can help...I'm really stuck and in a time cruch.
  18.  
  19. >I am taking a course in Graphics and decided to use the PC for my projects.
  20. >I just need to get a bare-bones app going so I can do my project.  I want
  21. >to create a simple window, create a bitmap in the window (so I can draw
  22. >to it), create a palette (aka color map) and get access to the palette to
  23. >change colors.
  24.  
  25. >I have everything working EXCEPT creating and modifying a palette.
  26. >Can someome PLEASE help me out with this.  My code is below.
  27. >If you already have a skeleton app that does what I'm looking for,
  28. >could you please email it to me or tell me what I did wrong?
  29. >(kevint@cs.wpi.edu)
  30.  
  31. >The code I have for creating a palette came directly from a Borland
  32. >example...but it doesn't work.  I'm using Borland C++ v4.5.
  33.  
  34. >Thank you,
  35.  
  36.  
  37. Hey Kevin,
  38.  
  39. First of all I couldn't find CreatePalette  in the Owl library but I
  40. did find it in the windows API.  If you desire to use the Windows API,
  41. the call should include double colons, ( ::CreatePalette).
  42.  
  43. Also in the example directory ( examples\owl\owlapi\palette) you can
  44. find a good example that will probably answer most of your questions.
  45.  
  46. Lastly, I wouldn't do all the Palette stuff in setupwindow.  I would
  47. do it in EvPaint or another event method (see example).
  48.  
  49. Hope this helps..
  50.  
  51. John
  52. >Kevin Theroux   :-)
  53.  
  54. >============================================================================
  55.  
  56. >#include <owl/owlpch.h>
  57. >#include <owl/applicat.h>
  58. >#include <owl/framewin.h>
  59. >#include <owl/dc.h>
  60. >#include <owl/inputdia.h>
  61. >#include <owl/color.h>
  62. >#include <stdlib.h>
  63.  
  64. >/*------------------------------------------------------------------------*/
  65.  
  66. >#define NUM_PALETTE_ENTRIES 128
  67.  
  68. >/*------------------------------------------------------------------------*/
  69.  
  70. >int          width, height;
  71. >HPALETTE     hpal;
  72. >PALETTEENTRY ape[NUM_PALETTE_ENTRIES];
  73. >LOGPALETTE*  plgpl;
  74.  
  75. >/*------------------------------------------------------------------------*/
  76.  
  77. >class myWindow : public TWindow
  78. >{
  79. >  TMemoryDC *myMemoryBitmap;  // this is where to draw to, then it is
  80. >                  // BitBlt'ed to the window
  81.  
  82. >  public:
  83. >     myWindow(TWindow* parent = 0);
  84. >     void SetupWindow();
  85. >    ~myWindow()
  86. >     {
  87. >     }
  88.  
  89. >  protected:
  90. >     // Message response functions
  91.  
  92. >  void Paint(TDC& dc, BOOL erase, TRect& rect);
  93. >};
  94.  
  95. >/*------------------------------------------------------------------------*/
  96.  
  97. >myWindow::myWindow(TWindow* parent)
  98. >{
  99. >    Init(parent, 0, 0);
  100. >}
  101.  
  102. >/*------------------------------------------------------------------------*/
  103.  
  104. >void
  105. >myWindow::Paint(TDC& dc, BOOL, TRect& )
  106. >{
  107. >    dc.BitBlt( GetClientRect(), *myMemoryBitmap, TPoint(0,0));
  108. >}
  109.  
  110. >/*------------------------------------------------------------------------*/
  111.  
  112. >void
  113. >myWindow::SetupWindow()
  114. >{
  115. >    int i, j, k, red, green, blue;
  116.  
  117. >    TWindow::SetupWindow();
  118.  
  119. >    myMemoryBitmap = new TMemoryDC( TClientDC (HWindow));
  120. >    myMemoryBitmap->SelectObject (TBitmap (width, height, 1, 32));
  121.  
  122. >    plgpl = (LOGPALETTE*) LocalAlloc (LPTR,
  123. >        sizeof(LOGPALETTE) + NUM_PALETTE_ENTRIES * sizeof(PALETTEENTRY));
  124.  
  125. >    plgpl->palNumEntries = NUM_PALETTE_ENTRIES;
  126. >    plgpl->palVersion = 0x300;
  127.  
  128. >    for (i = 0, red = 0, green = 127, blue = 127; i < NUM_PALETTE_ENTRIES;
  129. >         i++, red += 1, green += 1, blue += 1)
  130. >    {
  131. >         ape[i].peRed   = plgpl->palPalEntry[i].peRed   = LOBYTE(red);
  132. >         ape[i].peGreen = plgpl->palPalEntry[i].peGreen = LOBYTE(green);
  133. >         ape[i].peBlue  = plgpl->palPalEntry[i].peBlue  = LOBYTE(blue);
  134. >         ape[i].peFlags = plgpl->palPalEntry[i].peFlags = PC_RESERVED;
  135. >    }
  136.  
  137. >    hpal = CreatePalette(plgpl);  // * *  THIS ALWAYS RETURNS NULL  * *
  138.  
  139. >    AnimatePalette(hpal, 0, NUM_PALETTE_ENTRIES,
  140. >                       (PALETTEENTRY FAR*) &ape);
  141. >}
  142.  
  143. >/*------------------------------------------------------------------------*/
  144.  
  145. >class myApp : public TApplication {
  146. >  public:
  147. >     myApp() : TApplication() {}
  148.  
  149. >     void InitMainWindow()
  150. >     {
  151. >        TFrameWindow *my_FrameWindow = \
  152. >            new TFrameWindow(0, "Draw", new myWindow(0), true);
  153. >        
  154. >        width  = TScreenDC().GetDeviceCaps( HORZRES );
  155. >        height = TScreenDC().GetDeviceCaps( VERTRES );
  156.  
  157. >        my_FrameWindow->Attr.X = (width -600)/2;
  158. >        my_FrameWindow->Attr.Y = (height-400)/2-20;
  159.  
  160. >        SetMainWindow (my_FrameWindow);
  161. >     }
  162. >};
  163.  
  164. >/*------------------------------------------------------------------------*/
  165.  
  166. >int
  167. >OwlMain(int /*argc*/, char* /*argv*/ [])
  168. >{
  169. >  return myApp().Run();
  170. >}
  171.  
  172. >/*------------------------------------------------------------------------*/
  173.  
  174.  
  175.